<?php

namespace App\Console\Commands\Admin;

use App\Models\Admin\SysUser;
use Illuminate\Console\Command;

class AssignRolesForSysUser extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'admin:assign-roles {userId} {roleIds}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '为系统用户分配角色';

    /**
     * Execute the console command.
     */
    public function handle()
    {
        $user = SysUser::find($this->argument('userId'));
        $user->sysRoles()->sync(explode(',', $this->argument('roleIds')));
        // dd($user->roles->toArray());
        $this->info('done');
    }
}
